import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.image.ImageObserver;

/**
*	A class representing the LED panels on the top part of the minesweeper board.
*	Each of the LED panels consist of 3 'LED's.
*
**/
class LEDPanel 
{

	/**
	*	The value of the LED display.
	**/
	private int value;

	/**
	*	The internal padding 
	**/
	public static final int PIXELS_PADDING = 1;

	/**
	*	The beveld shading
	**/
	public static final int PIXELS_SLOPE = 1;


	private LED display[];
	

	public LEDPanel(int numLEDsInDisplay)
	{

		display = new LED[numLEDsInDisplay];

		for(int i=0;i<numLEDsInDisplay; i++)
		{
			
			display[i] = new LED();
		
		}

	}

	/**
	*	Get the value
	**/
	public int getValue()
	{

		return value;

	}

	/**
	*	Set the value
	**/
	public void setValue(int newVal)
	{

		value = newVal -1;
		increment();

	}

	/**
	*	Increment the display
	**/
	public void increment()
	{
		
		int div;
		value++;

		
		if (value >= (int)(Math.pow(10,display.length )))
		{
			value = (int)(Math.pow(10,display.length)) -1;
		}

		if (value <= -(int)(Math.pow(10,display.length-1 )))
		{
			value = -(int)(Math.pow(10,display.length-1))+1 ;
		}

		if(value < 0)//neg. values.
		{

			int tmp_val = -value;
			display[0].setValue(-1);
			for(int i=0;i<display.length-1;i++)
			{
				div = (int)(Math.pow(10,display.length - i -2));

				display[i+1].setValue(((-value/ div)) % 10);

			}


		}else
		{
			for(int i=0;i<display.length;i++)
			{

				div = (int)(Math.pow(10,display.length - i -1));
				display[i].setValue(((value/ div)) % 10);

			}
		}

	}

	/**
	*	Decrement the display
	**/
	public void decrement()
	{

		value = value - 2;
		increment();//use the increment to set the LEDs.

	}



	public void display(Graphics g,ImageObserver imOb,int x,int y)
	{

		g.setColor(Color.BLACK);//want to be able to change this later...


		g.fillRect(x,y,getDisplayWidth(),getDisplayHeight());
		//now do the shading.
		g.setColor(Game.INNER_SHADING);
		g.drawLine(x,y,x+getDisplayWidth()-1,y);
		g.drawLine(x-1,y,x-1,y+getDisplayHeight());

		g.setColor(Game.OUTER_SHADING);
		g.drawLine(x+getDisplayWidth()-1,y,
						x+getDisplayWidth()-1,y+getDisplayHeight());
		g.drawLine(x-1,y+getDisplayHeight(),
						x+getDisplayWidth()-1,y+getDisplayHeight());


		for(int i=0; i< display.length; i++)
		{

			display[i].displayLED(g,x + (i * (LED.PIXELS_WIDE +
					(PIXELS_PADDING * 2))  ) + PIXELS_PADDING + PIXELS_SLOPE ,
					y + PIXELS_PADDING + PIXELS_SLOPE);

		}


	}


	/**
	*	Get the width of this LED display panel, including the beveld
	*	surface used when drawing.
	**/
	public int getDisplayWidth()
	{

		return (display.length * ((PIXELS_PADDING * 2) + LED.PIXELS_WIDE)) + 
					(PIXELS_SLOPE * 2);

	}

	/**
	*	Get the height of this LED display panel, including the beveld
	*	surface used when drawing.
	**/
	public int getDisplayHeight()
	{

		return ((PIXELS_PADDING * 2) + LED.PIXELS_TALL) + 
					(PIXELS_SLOPE) * 2;

	}

	

}
